package cn.myschool.myschool.ctrl;

import cn.myschool.myschool.entity.Student;
import cn.myschool.myschool.service.IStudentService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author oldliu
 * @since 1.0
 */
@RestController
public class HelloController {
    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @Autowired
    private IStudentService studentService;

    @RequestMapping("studentpage")
    public Page<Student> search(@RequestParam(name = "pageNo",defaultValue = "1")int pageNo, @RequestParam(name = "sname",required = false)String sname){
        Page page = studentService.search(pageNo, 10, sname, null, null, null,null);
        redisTemplate.opsForValue().set("mystudents",page);
        redisTemplate.opsForValue().get("mystudents");
        return page;
    }

    public void test(@RequestHeader(value = "token",required = true)String t){

    }
}
